﻿using MvvmCross.Core.ViewModels;

namespace Sidvall.UI.Navigation
{
    public class HistoryRegionItem
    {
        public MvxViewModelRequest Request { get; set; }
        public string RegionName { get; set; }

        public void SetRequestParameterValue(object parameter)
        {
            if (parameter == null)
                return;
            if (this.Request == null)
                return;
            if (this.Request.ParameterValues == null)
                this.Request.ParameterValues = new System.Collections.Generic.Dictionary<string, string>();
            var type = parameter.GetType();
            var properties = Sidvall.SystemContext.Current.CodeManager.GetProperties(type, null, null, true, null);
            foreach (var property in properties)
            {
                var value = Sidvall.SystemContext.Current.CodeManager.GetPropertyValue(parameter, property);
                if (value != null)
                    this.Request.ParameterValues[property.Name] = value.ToString();
                else
                    this.Request.ParameterValues.Remove(property.Name);
            }
        }
        public void SetRequestParameterValue(string key, string value)
        {
            if (this.Request == null)
                return;
            if (this.Request.ParameterValues == null)
                this.Request.ParameterValues = new System.Collections.Generic.Dictionary<string, string>();
            this.Request.ParameterValues[key] = value;
        }
    }
}
